package com.slt.android.customview;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;

/**
 * Created by dp on 2017/12/14.
 */

public class ArcRecFView extends View {

    Paint paint1 = new Paint();
    Paint paint2 = new Paint();
    Paint paint3 = new Paint();
    Paint paint4 = new Paint();
//    Paint paint = new Paint();
//    Paint paint = new Paint();
    int screenWidth;
    int screenHeight;

    public ArcRecFView(Context context) {
        super(context);
        init(context);
    }

    public ArcRecFView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ArcRecFView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        Resources resources = this.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        paint1.setColor(Color.RED);
        paint2.setColor(Color.GREEN);
        paint3.setColor(Color.BLUE);
        paint4.setColor(Color.YELLOW);
    }



    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawRect(canvas);
        drawArc(canvas);
        drawCircle(canvas);
        drawText(canvas);
        
    }
    /** 画文字 */
    private void drawText(Canvas canvas) {
        canvas.drawText("成功没" , screenWidth/2 , screenHeight/2 , paint4);
    }

    /** 画内圆 */
    private void drawCircle(Canvas canvas) {
        canvas.drawCircle(screenWidth/2 , screenHeight/2 , screenWidth/4 , paint3);
    }

    /** 画圆弧 */
    private void drawArc(Canvas canvas) {
        RectF mRectF = new RectF(0 + 20 , (screenHeight - screenWidth)/2 + 20 , screenWidth -20, (screenHeight - screenWidth)/2 + screenWidth -20);
        paint2.setStrokeWidth(40);
        paint2.setStyle(Paint.Style.STROKE);
        canvas.drawArc(mRectF , -30 , 120 , false ,paint2);
    }

    /** 画正方形*/
    private void drawRect(Canvas canvas) {
        Rect mRect = new Rect(0 , (screenHeight - screenWidth)/2 , screenWidth , (screenHeight - screenWidth)/2 + screenWidth);
        canvas.drawRect(mRect , paint1);
    }
}
